package com.geek.bams.entity;


import com.geek.bams.exception.BalanceNotEnoughException;

import java.io.Serializable;

public class CreditAccount extends Account implements Serializable {
    private static final long serialVersionUID = 1L;
    private double ceiling; //信用额度

    public CreditAccount() {

    }

    /**
     * 取款方法
     * @param money  取钱
     * @return
     */
    @Override
    public Account withdraw(double money) throws BalanceNotEnoughException {
        if(this.getBalance() + this.ceiling >= money){
            if (money <= this.getBalance()){
                this.setBalance(this.getBalance() - money);
            }else{
                this.ceiling -= (money - this.getBalance());
                this.setBalance(0);
            }
        }else{
            throw new BalanceNotEnoughException("余额不足");
        }

        return this;
    }

    public CreditAccount(Long id, String name, String password, String personId, String email, double balance, double ceiling) {
        super(id, name, password, personId, email, balance);
        this.ceiling = ceiling;
    }

    public double getCeiling() {
        return ceiling;
    }

    public void setCeiling(double ceiling) {
        this.ceiling = ceiling;
    }

    @Override
    public String toString() {
        return "CreditAccount{" +
                "ceiling=" + ceiling +
                '}';
    }
}
